package com.wang.bean;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author wangf
 * @Description TODO
 * @Date 2023/9/3 20:06
 */
@Data
public class Result<T> implements Serializable {
    private Boolean success;
    private Integer code;
    private String message;
    private T data;

    public Result() {}

    public static Result ok() {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(ResultMessage.SUCCESS);
        return result;
    }

    public static <T> Result<T> ok(T data) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setData(data);
        result.setMessage(ResultMessage.SUCCESS);
        return result;
    }

    public static  Result ok(Integer code, String message) {
        Result result = new Result<>();
        result.setSuccess(true);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> ok(Integer code, String message, T data) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(code);
        result.setData(data);
        result.setMessage(message);
        return result;
    }


    public static Result fail() {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMessage.ERROR);
        return result;
    }

    public static <T> Result<T> fail(T data) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCode.ERROR);
        result.setData(data);
        result.setMessage(ResultMessage.ERROR);
        return result;
    }

    public static  Result fail(Integer code, String message) {
        Result result = new Result<>();
        result.setSuccess(true);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> fail(Integer code, String message, T data) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(code);
        result.setData(data);
        result.setMessage(message);
        return result;
    }


}
